package com.struts.web.manage.admin.corpor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.lg.system.CLGAction;
import com.lg.system.MessageBean;
import com.struts.deal.corpor.register.Deal;
import com.struts.web.corpor.manage.infomanage.EditInfoForm;

public class ImportCorporAction extends CLGAction {
	
	public ActionForward execute(ActionMapping actionMapping,
            ActionForm actionForm,
            HttpServletRequest request,
            HttpServletResponse response) throws
Exception {
		boolean result = false;
		ActionMessages msgs = new ActionMessages();
		EditInfoForm aWebForm = (EditInfoForm)actionForm;
		MessageBean messageBean = new MessageBean();
		String method = request.getParameter("method");
		System.out.println("method:"+method);
		
		if(aWebForm.getMethod()!=null && aWebForm.getMethod().equals("import")){
			//导入企业
			messageBean=Deal.importCorpor(request, response, aWebForm);
			if(messageBean.isResult()){
				return actionMapping.findForward("successmessages");
			}else{
				msgs.add("commonMsgs",new ActionMessage(messageBean.getMessage()));
				saveErrors(request,msgs);
			    return actionMapping.findForward("fail");
			}
		}else if(aWebForm.getMethod()!=null && aWebForm.getMethod().equals("import1")){
			//导入黑名单企业
			messageBean=Deal.importBlack(request, response, aWebForm);
			if(messageBean.isResult()){
				return actionMapping.findForward("successmessages");
			}else{
				msgs.add("commonMsgs",new ActionMessage(messageBean.getMessage()));
				saveErrors(request,msgs);
			    return actionMapping.findForward("fail");
			}
			
		}else if(aWebForm.getMethod()!=null && aWebForm.getMethod().equals("import2")){
			//导入求职者
			messageBean=Deal.importUser(request, response, aWebForm);
			if(messageBean.isResult()){
				return actionMapping.findForward("successmessages");
			}else{
				msgs.add("commonMsgs",new ActionMessage(messageBean.getMessage()));
				saveErrors(request,msgs);
			    return actionMapping.findForward("fail");
			}
		}
		return actionMapping.findForward("toQueryCorpor");
		
}

}
